package cn.wolfcode.luowowo2.articleserver.service.imp;

import cn.wolfcode.luowowo2.article.domain.Strategy;
import cn.wolfcode.luowowo2.article.mapper.StrategyMapper;
import cn.wolfcode.luowowo2.article.service.IStrategyService;
import cn.wolfcode.luowowo2.common.query.StrategyQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Albert on 2019/7/9.
 */
@Service
public class StrategyServiceImpl implements IStrategyService{
    @Autowired
    private StrategyMapper mapper;
    @Override
    public PageInfo<Strategy> query(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId()==null) {
            mapper.insert(strategy);
        }else {
            mapper.updateByPrimaryKey(strategy);
        }
    }

    @Override
    public List<Strategy> listAll() {
        return mapper.selectAll();
    }

    @Override
    public Strategy get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }
}
